package com.pand.model.customer;

import com.pand.model.BaseObject;
import com.pand.model.zmxy.CstExt;
import com.pand.util.DoubleUtils;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;

/**
 * 
 * @ClassName: Customer
 * @Description: 个人客户信息
 *
 */
@Entity
@Table(name = "BIZ_CUSTOMER")
@SequenceGenerator(name = "SeqCustomer", sequenceName = "SEQ_CUSTOMER", allocationSize = 1)
public class Customer extends BaseObject {
	/**
	 * @Fields serialVersionUID :
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 主键
	 */
	private Long id;

	/**
	 * 名字
	 */
	private String name;

	/**
	 * 性别
	 */
	private Integer sex;

	/**
	 * 生日
	 */
	private Timestamp birthday;

	/**
	 * 级别
	 */
	private CustomerLevel level;

	/**
	 * 手机号
	 */
	private String phone;

	/**
	 * 密码
	 */
	private String password;

	/**
	 * 支付密码
	 */
	private String payPassword;

	/**
	 * 状态
	 */
	private Integer state;

	/**
	 * 是否受限
	 */
	private Boolean isLimited;

	/**
	 * 证件id
	 */
	private Long certificateId;

	/**
	 * 证件编码
	 */
	private String certificateCode;

	/**
	 * 证件有效期
	 */
	private Timestamp certificateDeadline;

	/**
	 * 证件是否扫描
	 */
	private Integer certificateScanFlag;

	/**
	 * 证件正面图片路径
	 */
	private String certificateUrl;

	/**
	 * 身份证背面
	 */
	private String certificateBackUrl;

	/**
	 * 驾驶证
	 */
	private Integer drivingLicId;

	/**
	 * 驾驶证编号
	 */
	private String drivingLicCode;

	/**
	 * 驾驶证初领日期
	 */
	private Timestamp drivingLicStarttime;

	/**
	 * 驾驶证有效期
	 */
	private Timestamp drivingLicDeadline;

	/**
	 * 驾驶证是否扫描
	 */
	private Integer drivingLicScanFlag;

	/**
	 * 驾驶证照片地址
	 */
	private String drivingLicUrl;

	private String drivingLicAttUrl;

	/**
	 * 邮箱
	 */
	private String mail;

	/**
	 * 积分
	 */
	private Long score;

	/**
	 * 邀请码
	 */
	private String inviteCode;

	/**
	 * 推荐码
	 */
	private String recommandCod;

	/**
	 * 注册时间
	 */
	private Timestamp regTime;

	/**
	 * 是否认证
	 */
	private Integer isCheck = 0;

	/**
	 * 认证时间
	 */
	private Timestamp checkTime;

	/**
	 * 操作人
	 */
	private String checker;

	/**
	 * 地址
	 */
	private String sentAddress;

	/**
	 * 联系人名称
	 */
	private String contactName;

	/**
	 * 联系人电话
	 */
	private String contactPhone;

	/**
	 * 联系人关系
	 */
	private String contactRelation;

	/**
	 * 优惠券
	 */
	private Integer countCoupons;

	/**
	 * 注册类型 手机、网站、后台、微信
	 */
	private String registerType;

	/**
	 * 注册回访
	 */
	private Boolean isVisited;

	/**
	 * 是否被删除
	 */
	private Boolean isDeleted;

	/**
	 * 保证金
	 */
	private Double deposit;

	/**
	 * sessionkey
	 */
	private String sessionKey;

	/**
	 * app类型
	 */
	private String appType;

	/**
	 * 手机品牌
	 */
	private String phoneBrand;

	/**
	 * 手机型号
	 */
	private String phoneModel;

	/**
	 * 操作系统版本
	 */
	private String osVersion;

	/**
	 * 设备码
	 */
	private String imei;

	/**
	 * 设备标记
	 */
	private String deviceToken;

	/**
	 * 头像地址
	 */
	private String portrait;

	/**
	 * app版本
	 */
	private String appVersion;

	/**
	 * 订单总金额
	 */
	private Double orderAmount = 0d;

	/**
	 * 已开发票总金额
	 */
	private Double invoiceAmount = 0d;

	/**
	 * 可开发票金额
	 */
	private Double surplusInvoiceAmout;

	/**
	 * 昵称
	 */
	private String nickName;

	/**
	 * 客户任重
	 */
	private BizCustomerAuth bizCustomerAuth;

	/**
	 * 修改时间
	 */
	private Date uploadTime;

	/**
	 * 推荐码
	 */
	private String recommendCode;//

	/**
	 * 推荐给我的人的ID
	 */
	private Long recommendUser;

	/**
	 * 客户填写推荐码的时间
	 */
	private Timestamp recommendTime;

	/**
	 * 客户类型
	 */
	private Long customerType;

	/**
	 * 所属城市名称
	 */
	private String cityName;

	/**
	 * 芝麻信用
	 */
	private CstExt cstExt;

	/**
	 * 所属城市
	 */
	private String ownerCity;

	/**
	 * 注册城市
	 */
	private String registerCity;

	@Transient
	public String getOwnerCity() {
		return ownerCity;
	}

	public void setOwnerCity(String ownerCity) {
		this.ownerCity = ownerCity;
	}

	@Transient
	public String getRegisterCity() {
		return registerCity;
	}

	public void setRegisterCity(String registerCity) {
		this.registerCity = registerCity;
	}

	@Column(name = "CITY_NAME")
	public String getCityName() {
		return cityName;
	}

	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	@Column(name = "CUSTOMER_TYPE")
	public Long getCustomerType() {
		return customerType;
	}

	public void setCustomerType(Long customerType) {
		this.customerType = customerType;
	}

	@Transient
	public CstExt getCstExt() {
		return cstExt;
	}

	public void setCstExt(CstExt cstExt) {
		this.cstExt = cstExt;
	}

	@Column(name = "UPLOAD_TIME")
	public Date getUploadTime() {
		return uploadTime;
	}

	public void setUploadTime(Date uploadTime) {
		this.uploadTime = uploadTime;
	}

	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@JoinColumn(name = "Auth_ID")
	@NotFound(action = NotFoundAction.IGNORE)
	public BizCustomerAuth getBizCustomerAuth() {
		return bizCustomerAuth;
	}

	public void setBizCustomerAuth(BizCustomerAuth bizCustomerAuth) {
		this.bizCustomerAuth = bizCustomerAuth;
	}

	@Column(name = "NICKNAME")
	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	@Transient
	public Double getSurplusInvoiceAmout() {
		if (orderAmount == null) {
			return 0d;
		} else if (invoiceAmount == null) {
			return orderAmount;
		} else {
			return DoubleUtils.subtract(orderAmount, invoiceAmount);
		}
		// return surplusInvoiceAmout;
	}

	public void setSurplusInvoiceAmout(Double surplusInvoiceAmout) {
		this.surplusInvoiceAmout = surplusInvoiceAmout;
	}

	@Column(name = "ORDER_AMOUNT")
	public Double getOrderAmount() {
		return orderAmount;
	}

	public void setOrderAmount(Double orderAmount) {
		this.orderAmount = orderAmount;
	}

	@Column(name = "INVOICE_AMOUNT")
	public Double getInvoiceAmount() {
		return invoiceAmount;
	}

	public void setInvoiceAmount(Double invoiceAmount) {
		this.invoiceAmount = invoiceAmount;
	}

	@Id
	@GeneratedValue(generator = "SeqCustomer")
	@Column(name = "ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "NAME")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "SEX")
	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	@Column(name = "BIRTHDAY")
	public Timestamp getBirthday() {
		return birthday;
	}

	public void setBirthday(Timestamp birthday) {
		this.birthday = birthday;
	}

	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@JoinColumn(name = "CUSTOMER_LEVEL")
	public CustomerLevel getLevel() {
		return level;
	}

	public void setLevel(CustomerLevel level) {
		this.level = level;
	}

	@Column(name = "PHONE")
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "PASSWORD")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "PAY_PASSWORD")
	public String getPayPassword() {
		return payPassword;
	}

	public void setPayPassword(String payPassword) {
		this.payPassword = payPassword;
	}

	@Column(name = "STATE")
	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	@Column(name = "IS_LIMITED")
	public Boolean getIsLimited() {
		return isLimited;
	}

	public void setIsLimited(Boolean isLimited) {
		this.isLimited = isLimited;
	}

	@Column(name = "CERTIFICATE_ID")
	public Long getCertificateId() {
		return certificateId;
	}

	public void setCertificateId(Long certificateId) {
		this.certificateId = certificateId;
	}

	@Column(name = "CERTIFICATE_CODE")
	public String getCertificateCode() {
		return certificateCode;
	}

	public void setCertificateCode(String certificateCode) {
		this.certificateCode = certificateCode;
	}

	@Column(name = "CERTIFICATE_DEADLINE")
	public Timestamp getCertificateDeadline() {
		return certificateDeadline;
	}

	public void setCertificateDeadline(Timestamp certificateDeadline) {
		this.certificateDeadline = certificateDeadline;
	}

	@Column(name = "CERTIFICATE_SCAN_FLAG")
	public Integer getCertificateScanFlag() {
		return certificateScanFlag;
	}

	public void setCertificateScanFlag(Integer certificateScanFlag) {
		this.certificateScanFlag = certificateScanFlag;
	}

	@Column(name = "CERTIFICATE_URL")
	public String getCertificateUrl() {
		return certificateUrl;
	}

	public void setCertificateUrl(String certificateUrl) {
		this.certificateUrl = certificateUrl;
	}

	@Column(name = "CERTIFICATE_BACK_URL")
	public String getCertificateBackUrl() {
		return certificateBackUrl;
	}

	public void setCertificateBackUrl(String certificateBackUrl) {
		this.certificateBackUrl = certificateBackUrl;
	}

	@Column(name = "DRIVING_LIC_ID")
	public Integer getDrivingLicId() {
		return drivingLicId;
	}

	public void setDrivingLicId(Integer drivingLicId) {
		this.drivingLicId = drivingLicId;
	}

	@Column(name = "DRIVING_LIC_CODE")
	public String getDrivingLicCode() {
		return drivingLicCode;
	}

	public void setDrivingLicCode(String drivingLicCode) {
		this.drivingLicCode = drivingLicCode;
	}

	@Column(name = "DRIVING_LIC_STARTTIME")
	public Timestamp getDrivingLicStarttime() {
		return drivingLicStarttime;
	}

	public void setDrivingLicStarttime(Timestamp drivingLicStarttime) {
		this.drivingLicStarttime = drivingLicStarttime;
	}

	@Column(name = "DRIVING_LIC_DEADLINE")
	public Timestamp getDrivingLicDeadline() {
		return drivingLicDeadline;
	}

	public void setDrivingLicDeadline(Timestamp drivingLicDeadline) {
		this.drivingLicDeadline = drivingLicDeadline;
	}

	@Column(name = "DRIVING_LIC_SCAN_FLAG")
	public Integer getDrivingLicScanFlag() {
		return drivingLicScanFlag;
	}

	public void setDrivingLicScanFlag(Integer drivingLicScanFlag) {
		this.drivingLicScanFlag = drivingLicScanFlag;
	}

	@Column(name = "DRIVING_LIC_URL")
	public String getDrivingLicUrl() {
		return drivingLicUrl;
	}

	public void setDrivingLicUrl(String drivingLicUrl) {
		this.drivingLicUrl = drivingLicUrl;
	}

	@Column(name = "MAIL")
	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	@Column(name = "SCORE")
	public Long getScore() {
		return score;
	}

	public void setScore(Long score) {
		this.score = score;
	}

	@Column(name = "INVITE_CODE")
	public String getInviteCode() {
		return inviteCode;
	}

	public void setInviteCode(String inviteCode) {
		this.inviteCode = inviteCode;
	}

	@Column(name = "RECOMMAND_COD")
	public String getRecommandCod() {
		return recommandCod;
	}

	public void setRecommandCod(String recommandCod) {
		this.recommandCod = recommandCod;
	}

	@Column(name = "REG_TIME")
	public Timestamp getRegTime() {
		return regTime;
	}

	public void setRegTime(Timestamp regTime) {
		this.regTime = regTime;
	}

	@Column(name = "IS_CHECK")
	public Integer getIsCheck() {
		return isCheck;
	}

	public void setIsCheck(Integer isCheck) {
		this.isCheck = isCheck;
	}

	@Column(name = "CHECK_TIME")
	public Timestamp getCheckTime() {
		return checkTime;
	}

	public void setCheckTime(Timestamp checkTime) {
		this.checkTime = checkTime;
	}

	@Column(name = "CHECKER")
	public String getChecker() {
		return checker;
	}

	public void setChecker(String checker) {
		this.checker = checker;
	}

	@Column(name = "SENT_ADDRESS")
	public String getSentAddress() {
		return sentAddress;
	}

	public void setSentAddress(String sentAddress) {
		this.sentAddress = sentAddress;
	}

	@Column(name = "CONTACT_NAME")
	public String getContactName() {
		return contactName;
	}

	public void setContactName(String contactName) {
		this.contactName = contactName;
	}

	@Column(name = "CONTACT_PHONE")
	public String getContactPhone() {
		return contactPhone;
	}

	public void setContactPhone(String contactPhone) {
		this.contactPhone = contactPhone;
	}

	@Column(name = "CONTACT_RELATION")
	public String getContactRelation() {
		return contactRelation;
	}

	public void setContactRelation(String contactRelation) {
		this.contactRelation = contactRelation;
	}

	@Column(name = "REGISTER_TYPE")
	public String getRegisterType() {
		return registerType;
	}

	public void setRegisterType(String registerType) {
		this.registerType = registerType;
	}

	@Column(name = "IS_VISITED")
	public Boolean getIsVisited() {
		return isVisited;
	}

	public void setIsVisited(Boolean isVisited) {
		this.isVisited = isVisited;
	}

	@Column(name = "IS_DELETED")
	public Boolean getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(Boolean isDeleted) {
		this.isDeleted = isDeleted;
	}

	@Column(name = "DEPOSIT")
	public Double getDeposit() {
		return deposit;
	}

	public void setDeposit(Double deposit) {
		this.deposit = deposit;
	}

	@Column(name = "SESSIONKEY")
	public String getSessionKey() {
		return sessionKey;
	}

	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}

	@Column(name = "APPTYPE")
	public String getAppType() {
		return appType;
	}

	public void setAppType(String appType) {
		this.appType = appType;
	}

	@Column(name = "PHONEBRAND")
	public String getPhoneBrand() {
		return phoneBrand;
	}

	public void setPhoneBrand(String phoneBrand) {
		this.phoneBrand = phoneBrand;
	}

	@Column(name = "PHONEMODEL")
	public String getPhoneModel() {
		return phoneModel;
	}

	public void setPhoneModel(String phoneModel) {
		this.phoneModel = phoneModel;
	}

	@Column(name = "OSVERSION")
	public String getOsVersion() {
		return osVersion;
	}

	public void setOsVersion(String osVersion) {
		this.osVersion = osVersion;
	}

	@Column(name = "IMEI")
	public String getImei() {
		return imei;
	}

	public void setImei(String imei) {
		this.imei = imei;
	}

	@Column(name = "DEVICE_TOKEN")
	public String getDeviceToken() {
		return deviceToken;
	}

	public void setDeviceToken(String deviceToken) {
		this.deviceToken = deviceToken;
	}

	@Column(name = "APPVERSION")
	public String getAppVersion() {
		return appVersion;
	}

	public void setAppVersion(String appVersion) {
		this.appVersion = appVersion;
	}

	public String getPortrait() {
		return portrait;
	}

	public void setPortrait(String portrait) {
		this.portrait = portrait;
	}

	@Transient
	public Integer getCountCoupons() {
		return countCoupons;
	}

	public void setCountCoupons(Integer countCoupons) {
		this.countCoupons = countCoupons;
	}

	@Transient
	public String getSexText() {
		return sex == null ? "未知" : sex == 0 ? "女" : "男";
	}

	@Transient
	public String getLimitedText() {
		return isLimited != null && isLimited ? "是" : "否";
	}

	// 信用类型
	@Transient
	public String getCustomerCreditType() {
		return isLimited != null && isLimited ? "受限客户" : "正常客户";
	}

	@Transient
	public String getCheckText() {
		if (this.isCheck != null) {
			switch (this.isCheck) {
			case 0:
				return "未上传";
			case 1:
				return "认证通过";
			case 2:
				return "认证不通过";
			case 3:
				return "待审核";
			}
		}
		return "待上传";
	}

	@Transient
	public String getVisitText() {
		return isVisited != null && isVisited ? "已回访" : "尚未回访";
	}

	@Column(name = "RECOMMEND_CODE")
	public String getRecommendCode() {
		return recommendCode;
	}

	public void setRecommendCode(String recommendCode) {
		this.recommendCode = recommendCode;
	}

	@Column(name = "RECOMMEND_USER")
	public Long getRecommendUser() {
		return recommendUser;
	}

	public void setRecommendUser(Long recommendUser) {
		this.recommendUser = recommendUser;
	}

	@Column(name = "recommend_Time")
	public Timestamp getRecommendTime() {
		return recommendTime;
	}

	public void setRecommendTime(Timestamp recommendTime) {
		this.recommendTime = recommendTime;
	}

	@Column(name = "DRIVING_LIC_ATT_URL")
	public String getDrivingLicAttUrl() {
		return drivingLicAttUrl;
	}

	public void setDrivingLicAttUrl(String drivingLicAttUrl) {
		this.drivingLicAttUrl = drivingLicAttUrl;
	}
}
